package cn.tedu.hongbeifang.controller;

import cn.tedu.hongbeifang.pojo.dto.AdminAddNewDTO;
import cn.tedu.hongbeifang.pojo.dto.AdminLoginInfoDTO;
import cn.tedu.hongbeifang.service.IAdminService;
import cn.tedu.hongbeifang.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/")
@Api(tags = "01.管理员管理模块")
public class AdminController {


    @Autowired
    private IAdminService adminService;

    public AdminController(){
            log.debug("创建控制器类对象：xxController");
    }

    // http://localhost:9081/admins/login
    @PostMapping("/login")
    @ApiOperation("管理员登录")
    @ApiOperationSupport(order = 10)
    public JsonResult<String> login(@RequestBody AdminLoginInfoDTO adminLoginInfoDTO){
        log.debug("开始处理【管理员登录】的请求，参数：{}");
        String jwt = adminService.login(adminLoginInfoDTO);
        return JsonResult.ok(jwt);
    }

    // http://localhost:9081/admins/add-new
    @ApiOperation("添加管理员")
    @ApiOperationSupport(order = 100)
   // @PreAuthorize("hasAuthority('/ams/admin/add-new')")
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@RequestBody AdminAddNewDTO adminAddNewDTO) {
        log.debug("开始处理【添加管理员】的请求，参数：{}");
        adminService.addNew(adminAddNewDTO);
        return JsonResult.ok();
    }




}
